Skip to content

fix: sync bug fixes from the WasmEdge MLX plugin - #7

Merged
grorge123 merged 3 commits into
mainfrom
fix/sync-wasmedge-fixes
Nov 9, 2026
Merged

grorge123 merged 3 commits into
mainfrom
fix/sync-wasmedge-fixes

Conversation

@grorge123

@grorge123 grorge123 commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Ports bug fixes made to plugins/wasi_nn/MLX in WasmEdge back to this repo. WasmEdge-specific changes (namespaces, license headers, log prefixes, sv suffixes, WASI VFS) are left out.

Changes

  • whisper: remove shell command injection in loadAudio (cf. WasmEdge 4742d02fba)
    loadAudio joined the audio path into a command string and passed it to popen(), which runs it through /bin/sh. Shell metacharacters in the path (e.g. a.wav; rm -rf ~) ran arbitrary commands, and paths containing spaces broke.
    ffmpeg now runs via posix_spawnp with an argv array, so no shell is involved. Unlike WasmEdge, file-path input is kept because example/whisper.cpp and library users rely on it.

  • vlm: stop generation at EOS
    generate() always ran to MaxTokens. This adds a per-model virtual eosTokenIds(), and Gemma3 returns <eos> (1) and <end_of_turn> (106).
    WasmEdge hard-codes Token == 1 || Token == 106 in the shared loop. That would break mllama, where token 1 is " in the Llama 3 vocab, so the stop IDs are per-model here.

  • loadBytesFromFile: don't kill the process on failure (cf. WasmEdge 584437baa5)
    It now logs an error and returns an empty string instead of calling exit(1).

  • Rename shadowed identifiers (cf. WasmEdge e271503856)
    Renames parameters and locals that shadowed members or outer names in Module, Embedding/Linear, pooling, RotatingKVCache, and the whisper decoding and tokenizer code. No behavior change.

  • spdlog formatting (cf. WasmEdge 2b8429d303)
    Values are passed as {} format arguments instead of being concatenated into the format string.

  • ci: run macOS build on macos-latest
    GitHub no longer provides the macos-14 runner (The configuration 'macos-14-arm64-us-default' is not supported), so the macOS job was cancelled before it started.

  • build: drop unused fmt dependency
    CMakeLists.txt fetched and compiled fmt 10.2.1 but never linked or included it; spdlog uses its bundled copy. That fmt version fails to compile with the newer clang on macos-latest (consteval / FMT_STRING errors), so it is removed.

Not ported

  • WasmEdge's switch from const T& back to by-value parameters. This repo intentionally moved to const references in f1fffaf.
  • An unused flatten added to QuantizedEmbedding::forward in WasmEdge. It has no effect.
  • The Gemma3 attention-mask take(...) difference. Both versions look inconsistent with the Python reference mask[..., -K:], so this needs a separate look.

Testing

  • With clang + Ninja (the CI setup), the project sources compile: 29 of 30 translation units, including example/vlm.cpp, which includes the changed gemma3.h.
  • model/gemma3/gemma3.cpp fails locally with the same error on main. It's a local clang / GCC 15 libstdc++ issue and unrelated to this PR.
  • The full local build stops in third-party deps (sentencepiece, fmt) because the local compiler is newer, so the examples were not run end to end. Relying on CI for the full build.

🤖 Generated with Claude Code

grorge123 and others added 3 commits November 9, 2026 20:45
Port fixes made to plugins/wasi_nn/MLX in WasmEdge back to this repo:

- whisper: stop running ffmpeg through popen()/sh. loadAudio built a
  command string from the audio path, so shell metacharacters in the
  path could run arbitrary commands and paths with spaces broke.
  ffmpeg now runs via posix_spawnp with an argv array (cf. WasmEdge
  4742d02fba). File-path input is kept for library users.
- vlm: stop generation on the model's EOS tokens instead of always
  running to MaxTokens. Stop ids are a per-model virtual
  (eosTokenIds); Gemma3 returns <eos> (1) and <end_of_turn> (106).
  Unlike WasmEdge's hard-coded check, mllama is not affected.
- loadBytesFromFile: log and return an empty string on open failure
  instead of calling exit(1) (cf. WasmEdge 584437baa5).
- Rename parameters and locals that shadowed members or outer names in
  Module, Embedding/Linear, pooling, RotatingKVCache, whisper decoding
  and tokenizer (cf. WasmEdge e271503856).
- Pass values as spdlog format arguments instead of concatenating them
  into the format string (cf. WasmEdge 2b8429d303).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GitHub no longer provides the macos-14 runner, so the macOS job was
cancelled before it started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fmt was fetched and compiled but never linked or included; spdlog uses
its bundled copy. The pinned fmt 10.2.1 fails to compile with newer
clang (consteval FMT_STRING errors), which broke the macOS build on
macos-latest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@grorge123
grorge123 merged commit 4dec3b8 into main Nov 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant